<%-- 
    Document   : post-category-action
    Created on : Feb 13, 2012, 11:56:09 PM
    Author     : PhucAn
--%>
<%@page import="util.SharingUtil"%>
<%@page import="dto.PostCategory"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.PostCategoryDAO"%>
<%
PostCategoryDAO daoPostCate=new PostCategoryDAO();

//process button add click event
if(request.getParameter("add")!=null){
    PostCategory cate=new PostCategory();
    //cate.setId( Integer.parseInt(request.getParameter("id")));
    cate.setName(request.getParameter("name"));
    cate.setParentId((Integer.parseInt(request.getParameter("parent"))));
    if(daoPostCate.create(cate)>0){
        SharingUtil.showMessage(request, "New category is created");
    }else SharingUtil.showMessage(request, "Error occured. Category could not be created");
}
ArrayList<PostCategory> list=daoPostCate.getAllCategories();
request.setAttribute("list", list);
%>